﻿import VTitle from '@/components/common/MainTitle.vue'
import BasicForm from './BasicForm.vue'
// 生成菜单的页面
import VMenu from '@/components/SetMenu.vue'
// 预览
import BiPreview from '@/components/BiComponents/BiPreview.vue'
export default {
  components: {
    VTitle, BasicForm, VMenu, BiPreview
  },
  data () {
    return {
      titleName: '仪表板管理',
      tableData: [],
      tableColumn: [
        {
          text: '名称',
          indexName: 'title'
        },
        {
          text: '描述',
          indexName: 'desc'
        },
        {
          text: '路由',
          indexName: 'route'
        }
      ],
      // 基础信息维护的弹窗
      basicDialogInfo: {
        dialogFormVisible: false,
        operationType: '',
        rowInfo: null
      },
      // 页码部分
      totalLength: 0,
      // 获取表格数据的查询参数
      requestParams: {
        limit: 10,
        page: 1,
        filter: ''
      },
      loading: false,
      // 预览时
      previewVisible: false,
      previewUid: null,
      // 生成菜单的弹窗
      menuDialog: false,
      functionObj: ''
    }
  },
  created () {
    this.getAllPages()
  },
  methods: {
    // 初始化表格的数据
    getAllPages () {
      this.loading = true
      this.$get('/icpbidashboard', {
        limit: this.requestParams.limit,
        page: this.requestParams.page,
        filter: this.requestParams.filter
      }).then((data) => {
        let dataResult = data.data.result
        if (dataResult.code === 'success') {
          this.tableData = dataResult.data.QueryDatas
          this.totalLength = dataResult.data.TotalRow
          this.requestParams.page = dataResult.data.CurrentPage
        } else {
          this.$message({
            message: dataResult.msg,
            type: 'warning'
          })
        }
        this.loading = false
      }).catch((error) => {
        console.log(error)
        this.loading = false
      })
    },
    // 添加基础信息
    handleAdd () {
      this.basicDialogInfo.dialogFormVisible = true
      this.basicDialogInfo.operationType = 'add'
      this.basicDialogInfo.rowInfo = null
    },
    // 编辑基础信息
    handleEdit (row) {
      this.basicDialogInfo.dialogFormVisible = true
      this.basicDialogInfo.operationType = 'edit'
      this.basicDialogInfo.rowInfo = JSON.parse(JSON.stringify(row))
    },
    // 编辑或者新增成功时
    operationBasicSuccess () {
      this.basicDialogInfo.rowInfo = null
      this.basicDialogInfo.operationType = ''
      this.basicDialogInfo.dialogFormVisible = false
      this.getAllPages()
    },
    // 删除页面
    handleDelete (row) {
      this.$confirm('此操作将永久删除该仪表板, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonClass: 'el-button--info',
        cancelButtonText: '取消'
      }).then(() => {
        this.operationType = 'delete'
        this.deleteMethod(row.uid)
      }).catch(() => {})
    },
    // 删除的方法
    deleteMethod (uid) {
      this.loading = true
      this.$delete('/icpbidashboard/' + uid).then((data) => {
        if (data.status === 204) {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.getAllPages()
        } else {
          this.$message({
            message: data.statusText,
            type: 'warning'
          })
          this.loading = false
        }
      }).catch((error) => {
        console.log(error)
      })
    },
    // 查询时
    getSearchInfo () {
      this.requestParams.page = 1
      this.getAllPages()
    },
    // 底部页码的部分
    handleSizeChange (val) {
      this.requestParams.limit = val
      this.getAllPages()
    },
    handleCurrentChange (val) {
      this.requestParams.page = val
      this.getAllPages()
    },
    // 预览
    handlePreview (row) {
      if (row.uid) {
        this.previewVisible = true
        this.previewUid = row.uid
      }
    },
    // 配置设定
    handleSetting (row) {
      this.$router.push({
        path: '/dashboard/biSettings',
        query: {
          uid: row.uid
        }
      })
    },
    // 生成菜单
    handleMenu (row) {
      if (row.uid) {
        this.functionObj = {
          funcName: row.title,
          funcAuth: '',
          funcUid: row.uid,
          from: 'biMenu'
        }
        this.menuDialog = true
      }
    }
  }
}
